<%@page import="util.RequestStatusPrinter"%>
<%@page import="it.polimi.swimv2.entities.RequestStatus"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.util.*" %>
<%@ page import="it.polimi.swimv2.entities.*" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html dir="ltr" xmlns="http://www.w3.org/1999/xhtml">

<head>
<title>Swim 2.0</title>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<link href="layout.css" rel="stylesheet" type="text/css" />
<link href="style.css" rel="stylesheet" type="text/css" />
</head>

<body>


<div id="container">
<div id="masthead" class="navBG">
	<%@ include file="log.jsp" %>
</div>
	<div id="left_col" class="navBG">
		<%@ include file="menu.jsp" %>
	</div>
	<div id="page_content">
	<div class="tableTitle">
	Richieste Amicizia Ricevute:</div>
<% Collection<FriendshipRequest> receivedRequests = (Collection<FriendshipRequest>) request.getAttribute("receivedRequests");
	if(receivedRequests== null || receivedRequests.isEmpty()) {%>	
	<div class="heading">
	Non hai Richieste Amicizia Ricevute!</div>
<% }else{ %>
	
	<table class="resultTable">
	<tr>
		<td class="listTitle">Data</td>
		<td class="listTitle">Mittente</td>
		<td class="listTitle">Stato</td>
	</tr>
<% for(FriendshipRequest rq: receivedRequests){ %>
	<tr>
		<td class="listCell"><%= rq.getDate() %></td>
		<td class="listCell"><a href="UserProfileServlet?act=showUserProfile&username=<%= rq.getSender().getUsername() %>">
			<%= rq.getSender().getUsername() %> </a>
		</td>
		<td class="listCell">
<% if(rq.getStatus().equals(RequestStatus.Pending)) {%>
			<a href="FriendshipRequestServlet?act=acceptRequest&rqID=<%= rq.getId() %>">
			<input type="button" value="Accetta"/>	</a>
			<a href="FriendshipRequestServlet?act=refuseRequest&rqID=<%= rq.getId() %>">
			<input type="button" value="Rifiuta"/>	</a>	
<% }else{ %>	
			<%= RequestStatusPrinter.print(rq.getStatus())%>
<% } %>	
		</td>
	</tr>
<% } %>
	</table>
<% } %>	
	<div class="tableTitle">
	Richieste Amicizia Inviate:</div>
<% Collection<FriendshipRequest> sentRequests = (Collection<FriendshipRequest>) request.getAttribute("sentRequests");
	if(sentRequests== null || sentRequests.isEmpty()) {%>
	<div class="heading">
	Non hai Richieste Amicizia Inviate!</div>
<% }else{ %>
	
	<table class="resultTable">
	<tr>
		<td class="listTitle">Data</td>
		<td class="listTitle">Destinatario</td>
		<td class="listTitle">Stato</td>
	</tr>
<% for(FriendshipRequest rq: sentRequests){ %>
	<tr>
		<td class="listCell"><%= rq.getDate() %></td>
		<td class="listCell"><a href="UserProfileServlet?act=showUserProfile&username=<%= rq.getReceiver().getUsername() %>">
			<%= rq.getReceiver().getUsername() %> </a>
		</td>
		<td class="listCell">
<% if(rq.getStatus().equals(RequestStatus.Pending)) {%>
			<a href="FriendshipRequestServlet?act=cancelRequest&rqID=<%= rq.getId() %>">
			<input type="button" value="Annulla"/>	</a>
<% }else{ %>	
			<%= RequestStatusPrinter.print(rq.getStatus())%>
<% } %>
		</td>
	</tr>
<% } %>
	</table>
<% } %>	
	</div>
	<div id="footer" class="navBG">
	<p> Aliprandi-Belladelli </p>
</div>
</div>
</body>
</html>
